<?php
$id             = gpc_getIntPost("id",$id);
$groupname   	= gpc_getStringPost("GroupName");
$description    = gpc_getStringPost("Description");
$listname		= gpc_getStringArray('listname');

$str_permission = '';
foreach($listname as $i=> $name)
{
    $mods       = gpc_getStringArray($name);
    $mod        = 0;
    foreach($mods as $m)
    {
        $mod=$mod | intval($m);
    }
    $str_permission.=$name.':'.$mod.'|';
}


if(empty($groupname))
{
    error_transfer("Group name is Empty");
}

$id     = intval($id);

//check group exists:
$sql_select = "select iId from tblpermission where cGroupName='$groupname' and iId!=$id";
$rs=$dbsql->query($sql_select);
if($dbsql->num_rows($rs)>0)
{
    error_transfer("Group name is Exists");
}

if($act=="insert")
{
    $sql_insert="insert into tblpermission(cGroupName,cDescription,cPermission)
    					values('$groupname','$description','$str_permission')";
    $dbsql->query($sql_insert);

    page_transfer("Insert Group Success !","");
}
elseif($id>0)
{
    $sql_update = "UPDATE  tblpermission SET
    	  cGroupName     = '$groupname',
    	  cPermission	 = '$str_permission',
    	  cDescription   = '$description'
    	  WHERE  iId=$id";
    $dbsql->query($sql_update);

    page_transfer("Update Group Success !");
}
exit();
?>